package edu.com.wjt219971332.service.impl;

import edu.com.wjt219971332.entity.Competition;
import edu.com.wjt219971332.dao.CompetitionDao;
import edu.com.wjt219971332.service.CompetitionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;


@Service
public class CompetitionServiceImpl implements CompetitionService {
    @Autowired
    private CompetitionDao competitionDao;


    @Override
    public Competition queryById(Integer competitionid) {
        return this.competitionDao.queryById(competitionid);
    }


    @Override
    public Page<Competition> queryByPage(Competition competition, PageRequest pageRequest) {
        long total = this.competitionDao.count(competition);
        return new PageImpl<>(this.competitionDao.queryAllByLimit(competition, pageRequest), pageRequest, total);
    }


    @Override
    public int insert(Competition competition) {
        return this.competitionDao.insert(competition);
    }


    @Override
    public int update(Competition competition) {
        return  this.competitionDao.update(competition);
    }

    @Override
    public boolean deleteById(Integer competitionid) {
        return this.competitionDao.deleteById(competitionid) > 0;
    }

    @Override
    public List<Competition> queryByusername(String asinger) {
        return this.competitionDao.queryByusername(asinger);
    }
}
